package com.apes.fn.scm.appScan;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.apes.framework.api.SpringManager;
import com.apes.framework.plugin.esb.api.SimpleRequest;
import com.apes.scm.masterdata.party.model.PartyRole;
import com.apes.scm.masterdata.product.model.Product;
import com.apes.scm.masterdata.product.repository.ProductRepository;
import com.apes.scm.rbac.model.User;
import com.apes.scm.rbac.repository.UserRepository;

public interface Template {

    String[] identifys();

    JSONObject getOrder(String id);

    JSONArray getOrderLists(SimpleRequest request, String origin);

    void begin(String id, String userId);

    void cancel(String id, String userId);

    void submit(SimpleRequest request);

    // 获取操作员
    default PartyRole getCreator(SimpleRequest request) {
        String userId = request.get("CZYID");
        User user = SpringManager.getBean(UserRepository.class).findByOrigin(userId);
        if (user == null) throw new RuntimeException("未找到操作员信息！");
        return user.getPerson();
    }

    // 获取商品信息
    default Product getProduct(String origin) {
        Product product = SpringManager.getBean(ProductRepository.class).findOne(origin);
        if (product == null) throw new RuntimeException("商品信息不存在！外部编码：" + origin);
        return product;
    }

}
